<?php
/*
Primary Author: Alex Arey
Secondary: Derek Shue
Documentation: Cheng Yi
Updated: 12/10/2011
Module Description: The Internship Positions module adds/finds/updates/deletes Internship Positions from the database.
It also has the option of allowing Administrators to "accept" Internship Positions, allowing students to see them. 
*/
class Application_Model_DbTable_InternPositions extends Zend_Db_Table_Abstract
{

    protected $_name = 'INTERNPOSITIONS';

public function getNextKey(){
	$sqlquery = $this->select()->from($this->_name, array("MAX(POSID)"));
	$insertrow = $this->fetchRow($sqlquery)->toArray(); 
	return $insertrow["MAX(POSID)"] + 1;
}

public function getInternPosition($where)
    {
        $rows = $this->fetchRow($where);
        if (!$rows) {
            return null;
        }
        return $rows->toArray();
    }


public function getInternPositions($where)
    {
        $rows = $this->fetchAll($where);
        if (!$rows) {
            return null;
        }
        return $rows->toArray();
    }

    public function addInternPosition($cpid,$name,$startdate,$enddate,$responsibilities,$educationgoals,$skillqualifications,$programs,$majorimportance,$supervisor,$superiscontact,$structure,$support,$staff,$otherinterns,$description,$benefits,$positionsrequested,$positionsgranted, $term
)
    {
		$posid = $this->getNextKey();
        $data = array(
			'POSID' => $posid,
			'CPID' => $cpid,
			'NAME' => $name,
			'STARTDATE' => $startdate,
			'ENDDATE' => $enddate,
			'RESPONSIBILITIES' => $responsibilities,
			'EDUCATIONALGOALS' => $educationgoals,
			'SKILLSQUALIFICATIONS' => $skillqualifications,
			'PROGRAMS' => $programs,
			'MAJORIMPORTANCE' =>$majorimportance,
			'SUPERVISOR' => $supervisor,
			'SUPERISCONTACT' => $superiscontact,
			'STRUCTURE' => $structure,
			'SUPPORT' =>$support,
			'STAFF' => $staff,
			'OTHERINTERNS' => $otherinterns,
			'DESCRIPTION' => $description,
			'BENEFITS' => $benefits,
			'POSITIONSREQUESTED' => $positionsrequested,
			'POSITIONSGRANTED'=> $positionsgranted,
			'TERM' => $term
        );
        $this->insert($data);
		return $posid;
    }

    public function updateInternPosition($posid,$cpid,$name,$startdate,$enddate,$responsibilities,$educationgoals,$skillqualifications,$programs,$majorimportance,$supervisor,$superiscontact,$structure,$support,$staff,$otherinterns,$description,$benefits,$positionsrequested,$positionsgranted
)
    {
        $data = array(
            'CPID' => $cpid,
            'NAME' => $name,
			'STARTDATE' => $startdate,
			'ENDDATE' => $enddate,
			'RESPONSIBILITIES' => $responsibilities,
			'EDUCATIONGOALS' => $educationgoals,
			'SKILLQUALIFICATIONS' => $skillqualifications,
			'PROGRAMS' => $programs,
			'MAJORIMPORTANCE' =>$majorimportance,
			'SUPERVISOR' => $supervisor,
			'SUPERISCONTACT' => $superiscontact,
			'STRUCTURE' => $structure,
			'SUPPORT' =>$support,
			'STAFF' => $staff,
			'OTHERINTERNS' => $otherinterns,
			'DESCRIPTION' => $description,
			'BENEFITS' => $benefits,
			'POSITIONSREQUESTED' => $positionsrequested,
			'POSITIONSGRANTED'=> $positionsgranted,
			'TERM' => $term
        );
        $this->update($data, 'POSID = '. (int)$posid);
    }

    public function deleteInternPosition($posid)
    {
        $this->delete('POSID =' . (int)$posid);
    }


    public function acceptInternRequest($posid, $accept, $positionsgranted){
   		$data = array(
   			'ACCEPTED'=>$accept,
   			'POSITIONSGRANTED'=>$positionsgranted
   		);
    	$this->update($data, 'POSID = '. (int)$posid);
    }




/*
POSIDNUMBER
CPIDNUMBER
NAMEVARCHAR2
STARTDATEDATE
ENDDATEDATE
RESPONSIBILITIESVARCHAR2
EDUCATIONALGOALSVARCHAR2
SKILLSQUALIFICATIONSVARCHAR2
PROGRAMSVARCHAR2
MAJORIMPORTANCEVARCHAR2
SUPERVISORVARCHAR2
SUPERISCONTACTVARCHAR2
STRUCTUREVARCHAR2
SUPPORTVARCHAR2
STAFFNUMBER
OTHERINTERNSVARCHAR2
DESCRIPTIONVARCHAR2
BENEFITSVARCHAR2
POSITIONSREQUESTEDNUMBER
POSITIONSGRANTEDNUMBER
*/

}


























































































